﻿using UnityEngine;
using Mirror;
namespace NetTest
{
    public class CustomNetworkRoomManager : NetworkRoomManager
    {
        public override void OnRoomServerPlayersReady()
        {
            //base.OnRoomServerPlayersReady();
            if (allPlayersReady) 
            {
                Debug.Log("所有玩家都准备完毕");
                //Invoke(nameof(LoadGameScene),5);
                LoadGameScene();
            }
        }
        public void LoadGameScene() 
        {
            ServerChangeScene(GameplayScene);
        }

        public override GameObject OnRoomServerCreateGamePlayer(NetworkConnectionToClient conn, GameObject roomPlayer)
        {
            var customRoomPlayer =roomPlayer.GetComponent<CustomRoomPlayer>();

            if (customRoomPlayer != null&&customRoomPlayer.GamePlayer) 
            {
                Transform startPos = GetStartPosition();
                var gamePlayer = startPos != null
                    ? Instantiate(customRoomPlayer.GamePlayer, startPos.position, startPos.rotation)
                    : Instantiate(customRoomPlayer.GamePlayer, Vector3.zero, Quaternion.identity);
                return gamePlayer;
            }
            else 
            {
                return null;
            }
        }
    }
}
